package com.mobulasoft.calquest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.Toast;

/**
 * This class handles common tasks for all activities:
 * <ol>
 * <li>Hiding window title and setting content view (layout id)</li>
 * <li>Creating and handling options menu</li>
 * </ol>
 * @author Revivius
 *
 */
public class ActivityDecorator {

	/** Activity to decorate. */
	private Activity activity;
	
	public ActivityDecorator(Activity activity) {
		this.activity = activity;
	}
	
	public boolean onCreateOptionsMenu(Menu paramMenu) {
		activity.getMenuInflater().inflate(R.menu.menu, paramMenu);
		return true;
	}
	
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menu_home:
			//goHome();
			return true;
		case R.id.menu_about:
			activity.startActivityForResult(new Intent(activity, About.class), 0);
			return true;
		case R.id.menu_exit:
			// TODO: kill application
			return true;
		}

		return false;
	}
	
	public void prepareWindowAndContentView(Bundle paramBundle, int layoutId) {
		activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
		activity.setContentView(layoutId);
	}
	
	protected void warn(CharSequence message, int length) {
		Toast warning = Toast.makeText(activity, message, length);
		warning.setGravity(Gravity.CENTER, 0, 0);
		warning.show();
	}

	
}
